package com.pipayshop.service.impl;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.pipayshop.domain.BUserInfo;
import com.pipayshop.domain.StoreInfo;
import com.pipayshop.domain.StoreRegion;
import com.pipayshop.domain.StoreTags;
import com.pipayshop.domain.dto.*;
import com.pipayshop.domain.vo.*;
import com.pipayshop.entity.vo.BgImgVO;
import com.pipayshop.mapper.*;
import com.alibaba.fastjson.JSON;
import com.pipayshop.service.PhysicalStoreInfoService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.javadocmd.simplelatlng.LatLngTool;
import com.javadocmd.simplelatlng.util.LengthUnit;
import com.pipayshop.entity.UserInfo;
import com.pipayshop.exception.BusinessException;
import com.pipayshop.mapper.ImageMapper;
import com.pipayshop.mapper.UserInfoMapper;
import com.pipayshop.utils.*;
import jakarta.annotation.Resource;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.text.DecimalFormat;
import java.util.*;
import java.util.stream.Collectors;

import com.google.common.collect.Sets;
import com.javadocmd.simplelatlng.LatLng;

/**
 * <p>
 * 实体店的信息 服务实现类
 * </p>
 *
 * @author nws
 * @since 2023-07-25
 */
@Service
public class PhysicalStoreInfoServiceImpl extends ServiceImpl<PhysicalStoreInfoMapper, StoreInfo> implements PhysicalStoreInfoService {

    @Resource
    private PhysicalStoreInfoMapper shopInfoMapper;

    @Resource
    private PhysicalStoreTagsMapper tagMapper;
    @Resource
    private UserInfoMapper userInfoMapper;

    private final static Set<String> USER_ID_LIST = Sets.newConcurrentHashSet();

    @Resource
    private PhysicalBUserInfoMapper bUserInfoMapper;

    @Resource
    private ImageMapper imageMapper;

    @Resource
    private PhysicalStoreCategoryMapper shopCategoryMapper;

    @Resource
    private PhysicalCountrySecondMapper countrySecondMapper;

    @Resource
    private PhysicalCountryThirdMapper countryThirdMapper;

    @Autowired
    private PhysicalStoreRegionMapper shopRegionMapper;

    @Resource
    private PhysicalCountryFourthMapper countryFourthMapper;

    private final RedisUtil<CountryMinVO> redisUtil = new RedisUtil<>();

    @Override
    public String getShopCodeByShopId(String shopId) {
        return shopInfoMapper.getShopCodeByShopId(shopId);
    }

    /**
     * 首页获取所有实体店列表
     */
    @Override
    public PageDataVO getShopInfoListByCondition(StoreInfoListByConditionDTO shopInfoListByConditionDTO) {
        ValidationUtil.validateString(shopInfoListByConditionDTO.getRegionId(), "region_id_required");
        // 获取总条数
        Integer count = shopInfoMapper.getIndexShopInfoVOCount(shopInfoListByConditionDTO.getCategoryId(), shopInfoListByConditionDTO.getRegionId(), shopInfoListByConditionDTO.getShopName());
        List<IndexShopInfoVO> indexShopInfoVO = shopInfoMapper.getIndexShopInfoVO(shopInfoListByConditionDTO.getCategoryId(),
                (shopInfoListByConditionDTO.getPages() - 1) * shopInfoListByConditionDTO.getLimit(),
                shopInfoListByConditionDTO.getLimit(),
                shopInfoListByConditionDTO.getScore(),
                shopInfoListByConditionDTO.getRegionId(),
                shopInfoListByConditionDTO.getShopName());
        indexShopInfoVO
                .stream()
                .parallel()
                .forEach(shopInfoVO -> {
                    List<String> list1 = new ArrayList<>();
                    List<String> list = JSON.parseArray(shopInfoVO.getTagList(), String.class);
                    if (list == null || list.isEmpty()) {
                        return;
                    }
                    for (String tagId : list) {
                        String tagContent = tagMapper.selectOneContent(tagId);
                        list1.add(tagContent);
                    }
                    shopInfoVO.setShopTagsList(list1);
                });
        return new PageDataVO(count, indexShopInfoVO);
    }

    //获取自营店信息列表
    @Override
    public PageDataVO getInquireShop(StoreInfoListByConditionDTO shopInfoListByConditionDTO) {
        ValidationUtil.validateString(shopInfoListByConditionDTO.getRegionId(), "region_id_required");

        // 获取总条数
        Integer count = shopInfoMapper.getIndexShopInfoVOCount(shopInfoListByConditionDTO.getCategoryId(), shopInfoListByConditionDTO.getRegionId(), shopInfoListByConditionDTO.getShopName());
        List<IndexShopInfoVO> indexShopInfoVO = shopInfoMapper.getInquireShopInfoVO(shopInfoListByConditionDTO.getCategoryId(),
                (shopInfoListByConditionDTO.getPages() - 1) * shopInfoListByConditionDTO.getLimit(),
                shopInfoListByConditionDTO.getLimit(),
                shopInfoListByConditionDTO.getScore(),
                shopInfoListByConditionDTO.getRegionId(),
                shopInfoListByConditionDTO.getShopName());
        indexShopInfoVO
                .stream()
                .parallel()
                .forEach(shopInfoVO -> {
                    List<String> list1 = new ArrayList<>();
                    List<String> list = JSON.parseArray(shopInfoVO.getTagList(), String.class);
                    if (list == null || list.isEmpty()) {
                        return;
                    }
                    for (String tagId : list) {
                        String tagContent = tagMapper.selectOneContent(tagId);
                        list1.add(tagContent);
                    }
                    shopInfoVO.setShopTagsList(list1);
                });
        return new PageDataVO(count, indexShopInfoVO);
    }

    /**
     * 处理实体店响应实体(距离)
     */
    private List<StoreInfoVO> getShopVO(List<StoreInfo> result, StoreDTO shopDTO) {
        List<StoreInfoVO> container = new ArrayList<>();
        if (result == null) {
            return container;
        }
        result.stream().forEach(shopInfo -> {
            StoreInfoVO vo = new StoreInfoVO();
            vo.setShopId(shopInfo.getShopId());
            vo.setShopName(shopInfo.getShopName());
            vo.setAddress(shopInfo.getAddress());
            vo.setScore(shopInfo.getScore());
            vo.setShopIntroduce(shopInfo.getShopIntroduce());
            // 处理标签列表
            String tagList = shopInfo.getTagList();
            if (tagList != null) {
                String[] split = tagList.split(",");
                List<StoreTags> tagsList = tagMapper.selectList(new LambdaQueryWrapper<StoreTags>()
                        .in(StoreTags::getTagId, split));
                vo.setShopTagsList(tagsList);
            }
            vo.setDistance(calculateDistance(shopDTO, shopInfo));
            container.add(vo);
        });
        return container;
    }

    /**
     * 根据用户定位 以及 商家位置  计算两者距离
     *
     * @param shopDTO  用户经纬度
     * @param shopInfo 商家经纬度
     * @return 00.00km
     */
    private static String calculateDistance(StoreDTO shopDTO, StoreInfo shopInfo) {
        if (shopDTO.getLatitude() == null && shopDTO.getLongitude() == null) {
            return null;
        }
        // 定义两个经纬度点
        // 用户所在的经纬度
        LatLng point1 = new LatLng(shopDTO.getLatitude().doubleValue(), shopDTO.getLongitude().doubleValue());
        // 商家所在的经纬度
        LatLng point2 = new LatLng(shopInfo.getLocalhostLatitude().doubleValue(), shopInfo.getLocalhostLongitude().doubleValue());
        // 计算两点之间的距离（单位：千米）
        double distance = LatLngTool.distance(point1, point2, LengthUnit.KILOMETER);
        DecimalFormat decimalFormat = new DecimalFormat("#.##");
        String r = decimalFormat.format(distance);

        return r + "km";
    }

    /**
     * 根据实体店id查询实体店信息
     */
    @Override
    public StoreInfoVO getShopInfoById(String shopId) {
        StoreInfoVO shopInfoVO = new StoreInfoVO();
        StoreInfo shopInfo = shopInfoMapper.selectOne(new QueryWrapper<StoreInfo>()
                .eq("status", 0)
                .eq("shop_id", shopId));

        BeanUtils.copyProperties(shopInfo, shopInfoVO);
        // 解析imageList数据
        List<String> imageList = JSON.parseArray(shopInfo.getShopImagList(), String.class);
        // 使用 LinkedHashSet 保证去重的同时保留原有顺序
        Set<String> uniqueImages = new LinkedHashSet<>(imageList);

        // 转回 List（如果需要）
        List<String> distinctImageList = new ArrayList<>(uniqueImages);

        // 设置到 VO 对象中
        shopInfoVO.setShopImagListCode(distinctImageList);
        List<String> images = imageList.stream()
                .parallel()
                .map(imageId -> imageMapper.selectPath(imageId))
                .collect(Collectors.toList());

        Map<String, String> imageMap = new HashMap<>();
        // 将 imageList 中的元素和 images 中对应的元素一一存入 imageMap
        for (int i = 0; i < imageList.size(); i++) {
            imageMap.put(imageList.get(i), images.get(i));
        }
        shopInfoVO.setShopImagList(imageMap);
        shopInfoVO.setUserImageCode(shopInfoVO.getUserImage());
        shopInfoVO.setUserImage(imageMapper.selectPath(shopInfoVO.getUserImage()));
        // 解析qrcode数据
        shopInfoVO.setQrcodeCode(shopInfo.getQrcode());
        shopInfoVO.setQrcode(imageMapper.selectPath(shopInfo.getQrcode()));
        // 解析categoryId数据
        shopInfoVO.setCategoryId(shopCategoryMapper.selectContent(shopInfo.getCategoryId()));
        shopInfoVO.setCategoryIdCode(shopInfo.getCategoryId());
        return shopInfoVO;

    }

    /**
     * 根据用户id查询用户名下多少间实体店
     */
    @Override
    public Integer getShopNumber(String uid) {
        Long count = shopInfoMapper.selectCount(new QueryWrapper<StoreInfo>()
                .eq("uid", uid));
        return Math.toIntExact(count);
    }

    /**
     * 根据用户id查询实体店列表(我的)
     */
    @Override
    public PageDataVO getShopList(UidPageVO uidPageVO) {
        Integer shopNumber = shopInfoMapper.getShopNumber(uidPageVO.getUid());
        if (uidPageVO.getPage() == 0) throw new BusinessException("page_number_invalid");
        List<StoreInfoVO1> shopList = shopInfoMapper.getShopList((uidPageVO.getPage() - 1) * uidPageVO.getLimit(), uidPageVO.getLimit(), uidPageVO.getUid());
        return new PageDataVO(shopNumber, shopList);
    }

    /**
     * 根据实体店id查询实体店信息(我的)
     */
    @Override
    public StoreInfoVO1 getShopInfoVO(String shopId) {
        return shopInfoMapper.getShopInfoVO(shopId);
    }

    /**
     * 根据实体店id上下架实体店
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteShopInfoById(String shopId, Integer status) {
        // 检查参数
        if (status == null) {
            throw new BusinessException("status_required");
        }
        if (status != 0 && status != 1) {
            throw new BusinessException("invalid_status");
        }

        // 更新店铺状态
        int update = shopInfoMapper.update(null, new UpdateWrapper<StoreInfo>()
                .eq("shop_id", shopId)
                .eq("status", (status == 0) ? 1 : 0) // 匹配当前状态
                .set("status", status) // 设置为目标状态
        );
        // 检查更新结果
        if (update == 0) {
            String message = (status == 0) ? "store_not_found_or_already_online" : "store_not_found_or_already_offline";
            throw new BusinessException(message);
        }
    }


    /**
     * 根据实体店id修改实体店
     */
    @Override
    public void updateShopInfoById(StoreInfoDTO shopInfoDTO) {
        // 数据筛查
        ValidationUtil.validateNotNull(shopInfoDTO, "store_info_empty");
        ValidationUtil.validateString(shopInfoDTO.getShopName(), "shop_name_required");
        ValidationUtil.validateNotNull(shopInfoDTO.getLocalhostLatitude(), "store_coordinates_empty");
        ValidationUtil.validateNotNull(shopInfoDTO.getLocalhostLongitude(), "store_coordinates_empty");
        ValidationUtil.validateString(shopInfoDTO.getPhone(), "contact_phone_required");
        ValidationUtil.validateString(shopInfoDTO.getAddress(), "store_address_empty");
        ValidationUtil.validateString(shopInfoDTO.getUserImage(), "store_avatar_empty");
        ValidationUtil.validateNotNull(shopInfoDTO.getCategoryId(), "store_category_empty");
        ValidationUtil.validateNotNull(shopInfoDTO.getStartTime(), "business_hours_required");
        ValidationUtil.validateNotNull(shopInfoDTO.getEndTime(), "business_hours_required");
        if (shopInfoDTO.getDeleteImageList() != null && !shopInfoDTO.getDeleteImageList().isEmpty()) {
            if (shopInfoMapper.updateDelFlag(shopInfoDTO.getDeleteImageList()) == 0) {
                throw new BusinessException("image_usage_update_failed");
            }
        }

        // 将图片列表转换为JSON字符串
        ObjectMapper objectMapper = new ObjectMapper();
        try {
            String json = objectMapper.writeValueAsString(shopInfoDTO.getShopImagList());
            shopInfoDTO.setShopImagListString(json);
        } catch (JsonProcessingException e) {
            throw new BusinessException("image_list_conversion_failed", e);
        }

        // 更新店铺信息
        int i = shopInfoMapper.updateShopInfoById(shopInfoDTO);
        if (i == 0) {
            throw new BusinessException("modify_failed");
        }
    }


    /**
     * 申请实体店
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void applyShop(ApplyShopDTO applyShopDTO) {
        ValidationUtil.validateNotNull(applyShopDTO, "application_data_empty");
        ValidationUtil.validateListNotEmpty(applyShopDTO.getShopImagList(), "physical_store_image_empty");
        ValidationUtil.validateString(applyShopDTO.getAddress(), "store_address_empty");
        ValidationUtil.validateString(applyShopDTO.getCategoryId(), "store_category_empty");
        ValidationUtil.validateString(applyShopDTO.getRegionId(), "region_id_required");
        if (!USER_ID_LIST.add(applyShopDTO.getUid())) {
            throw new BusinessException("duplicate_submission_not_allowed");
        }
        try {
            String uid = applyShopDTO.getUid();
            // 检查用户是否存在且状态为正常
            UserInfo userInfo = userInfoMapper.selectOne(new QueryWrapper<UserInfo>()
                    .eq("uid", uid)
                    .eq("status", 0));
            if (userInfo == null) {
                throw new BusinessException("apply_store_failed");
            }
            // 检查用户是否为VIP用户
            Integer membership = 1; // 这里可以根据需要修改，先假设为普通用户
            // Integer membership = userInfo.getLevel();

            // 属性转移到实体类
            StoreInfo shopInfo = new StoreInfo();
            BeanUtils.copyProperties(applyShopDTO, shopInfo);
            String shopId = StringUtil.generateShortId();
            shopInfo.setShopId(shopId);
            List<String> shopImagList = applyShopDTO.getShopImagList();
            shopInfo.setShopImagList(JSON.toJSONString(shopImagList.subList(1, shopImagList.size())));
            shopInfo.setUserImage(shopImagList.get(0));  // 设定店铺头像
            shopInfo.setUid(uid);
            shopInfo.setMembership(membership);  // 设置会员等级
            shopInfo.setPiratio(applyShopDTO.getPiratio());  // 设置店铺比例
            log.error("shopInfo: " + shopInfo);

            // 新增实体店
            int insert = shopInfoMapper.insert(shopInfo);
            if (insert < 1) {
                throw new BusinessException("apply_store_failed");
            }

            // 用户可绑定实体店剩余数量减一
            int update = userInfoMapper.update(null, new LambdaUpdateWrapper<UserInfo>()
                    .eq(UserInfo::getUid, applyShopDTO.getUid())
                    .eq(UserInfo::getStatus, 0)
                    .gt(UserInfo::getShopBalance, 0)
                    .setSql("shop_balance = shop_balance - 1"));
            if (update < 1) {
                throw new BusinessException("apply_store_failed");
            }

            // 存入实体店分区表
            StoreRegion shopRegion = new StoreRegion(null, applyShopDTO.getRegionId(), shopId, null, null);
            int insertRegion = shopRegionMapper.insert(shopRegion);
            if (insertRegion < 1) {
                throw new BusinessException("apply_store_failed");
            }

            // 如果是第一次绑定实体店的话要给他分配一个B端账号
            Long shopSum = shopInfoMapper.selectCount(new QueryWrapper<StoreInfo>().eq("uid", uid));
            if (shopSum == 0) {
                // 注册一个B端账号
                Date date = new Date();
                BUserInfo bUserInfo = new BUserInfo(null, userInfo.getPiName(), userInfo.getPiName(),
                        date, date, date, 0);
                int insertBUser = bUserInfoMapper.insert(bUserInfo);
                if (insertBUser < 1) {
                    throw new BusinessException("apply_store_failed");
                }
            }

        } catch (Exception e) {
            log.error("apply_store_failed", e);
            throw new BusinessException("apply_store_failed");
        } finally {
            USER_ID_LIST.remove(applyShopDTO.getUid());  // 清除重复提交的标记
        }
    }


    /**
     * 根据一级分类-获取所有实体店列表
     */
    @Override
    public PageDataVO getSecShopInfoListByCondition(SecShopInfoListByConditionDTO secShopInfoListByConditionDTO) {
        ValidationUtil.validateString(secShopInfoListByConditionDTO.getRegionId(), "region_id_required");
        ValidationUtil.validateString(secShopInfoListByConditionDTO.getCategoryId(), "category_required");
        Integer count = shopInfoMapper.getAllIndexShopInfoVO(secShopInfoListByConditionDTO.getCategoryId(), secShopInfoListByConditionDTO.getRegionId(), secShopInfoListByConditionDTO.getShopName());
        // stata==1,按评分从低到高；stata==2,按评分从高到低
        List<IndexShopInfoVO> indexShopInfoVO = shopInfoMapper.getIndexShopInfoVOById(secShopInfoListByConditionDTO.getCategoryId(),
                (secShopInfoListByConditionDTO.getPages() - 1) * secShopInfoListByConditionDTO.getLimit(),
                secShopInfoListByConditionDTO.getLimit(),
                secShopInfoListByConditionDTO.getRegionId(), secShopInfoListByConditionDTO.getShopName());
        for (IndexShopInfoVO shopInfoVO : indexShopInfoVO) {
            List<String> list1 = new ArrayList<>();
            List<String> list = JSON.parseArray(shopInfoVO.getTagList(), String.class);
            if (list == null || list.isEmpty()) {
                continue;
            }
            for (String s : list) {
                String tag_id = tagMapper.selectOneContent(s);
                list1.add(tag_id);
            }

            shopInfoVO.setShopTagsList(list1);
        }
        return new PageDataVO(count, indexShopInfoVO);
    }


    @Override
    public boolean isVipShop(String shopId) {
        int count = shopInfoMapper.selectCount(new QueryWrapper<StoreInfo>()
                .eq("shop_id", shopId)
                .eq("status", 0)
                .eq("membership", 1)).intValue();
        return count == 1;
    }

    @Override
    public List<String> getShopIdListByUid(String uid) {
        return shopInfoMapper.getShopIdListByUid(uid);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean upVipByShopIdList(String shopIds) {
        String[] shopIdArray = shopIds.split(",");
        long count = Arrays.stream(shopIdArray)
                .peek(shopId -> {
                    shopInfoMapper.update(null, new UpdateWrapper<StoreInfo>()
                            .eq("shop_id", shopId)
                            .eq("status", 0)
                            .set("membership", 1));
                }).count();
        return true;
    }

    /**
     * 查询指定实体店还可以上传的商品数量
     */
    @Override
    public Integer updateShopCommodity(String shopId) {
        return shopInfoMapper.updateAllNumber(shopId);
    }

    @Override
    public CheckVO checkId(String qrcode) {
        // ShopInfo shopInfo = shopInfoMapper.selectOne(new QueryWrapper<ShopInfo>().eq("qrcode", qrcode)
        //         .eq("status", 0));
        // if(qrcode.startsWith("payapp.weixin.qq.com")||qrcode.startsWith("payapp.wechatpay.cn")){
        //     qrcode = qrcode+"#wechat_pay";
        // }
        StoreInfo shopInfo = shopInfoMapper.selectShopInfoByQrcode(qrcode);
        if (shopInfo == null) {
            return null;
        }
        return new CheckVO(shopInfo.getShopId(), shopInfo.getShopName(), shopInfo.getUserImage());
    }

    @Override
    public Boolean setShopScore() {
        Integer update = shopInfoMapper.setItemScore();
        return update > 0;
    }


    @Override
    public String shopTopImageUp(MultipartFile multipartFile) {
        List<String> imageSizeList = new ArrayList<>();
        imageSizeList.add(ImageConstants.SHOP_TOP_IMAGE_UP_SMALL);
        return FileUploadUtil.allUploadImageData(multipartFile, imageMapper, FileUploadUtil.STORE_TOP_IMAGE_UP, imageSizeList);
    }

    @Override
    public String shopImageUp(MultipartFile multipartFile) {
        List<String> imageSizeList = new ArrayList<>();
        imageSizeList.add(ImageConstants.SHOP_IMAGE_UP_BIG);
        return FileUploadUtil.allUploadImageData(multipartFile, imageMapper, FileUploadUtil.STORE_IMAGE_UP, imageSizeList);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<CountryMinVO> getSecondDistrictList(String countryCode) {
        // 直接走缓存拿
        List<CountryMinVO> dataListFromRedisList = redisUtil.getDataListFromRedisList(Constants.COUNTRY_SECOND_REGION + "_" + countryCode);
        // 校验缓存结果
        if (dataListFromRedisList == null || dataListFromRedisList.size() == 0) {
            // 刷新缓存
            dataListFromRedisList = countrySecondMapper.getSecondDistrictList(countryCode);
            if (dataListFromRedisList == null || dataListFromRedisList.size() == 0) {
                return null;
            }
            redisUtil.savaDataListToRedisList(Constants.COUNTRY_SECOND_REGION + "_" + countryCode, dataListFromRedisList);
        }
        return dataListFromRedisList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<CountryMinVO> getThirdDistrictList(String countrySecondId) {
        // 直接走缓存拿
        List<CountryMinVO> dataListFromRedisList = redisUtil.getDataListFromRedisList(Constants.COUNTRY_THIRD_REGION + "_" + countrySecondId);
        // 校验缓存结果
        if (dataListFromRedisList == null || dataListFromRedisList.size() == 0) {
            // 刷新缓存
            dataListFromRedisList = countryThirdMapper.getThirdDistrictList(countrySecondId);
            if (dataListFromRedisList == null || dataListFromRedisList.size() == 0) {
                return null;
            }
            redisUtil.savaDataListToRedisList(Constants.COUNTRY_THIRD_REGION + "_" + countrySecondId, dataListFromRedisList);
        }
        return dataListFromRedisList;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public List<CountryMinVO> getFourthDistrictList(String countryThirdId) {
        // 直接走缓存拿
        List<CountryMinVO> dataListFromRedisList = redisUtil.getDataListFromRedisList(Constants.COUNTRY_FOURTH_REGION + "_" + countryThirdId);
        // 校验缓存结果
        if (dataListFromRedisList == null || dataListFromRedisList.size() == 0) {
            // 刷新缓存
            dataListFromRedisList = countryFourthMapper.getFourthDistrictList(countryThirdId);
            if (dataListFromRedisList == null) {
                return null;
            }
            redisUtil.savaDataListToRedisList(Constants.COUNTRY_THIRD_REGION + "_" + countryThirdId, dataListFromRedisList);
        }
        return dataListFromRedisList;
    }

    @Override
    public int deleteShopById(String shopId) {
        UpdateWrapper<StoreRegion> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("shop_id", shopId).set("del_flag", 1);
        shopRegionMapper.update(null, updateWrapper);
        return shopInfoMapper.deleteShopById(shopId);
    }


}
